<style>
    #oilPrice-add {
        padding: 20px 25px 25px 0;
    }
    #oilPrice-add .layui-treeSelect .ztree li a, .ztree li span {
        margin: 0 0 2px 3px !important;
    }
</style>
<div class="layui-fluid" id="oilPrice-add">
    <form class="layui-form" action="" lay-filter="oilPrice-add-form">
        <div class="layui-form-item">
            <label class="layui-form-label febs-form-item-require">字典名称：</label>
            <div class="layui-input-block">
                <input style="display: none" type="text" name="id" maxlength="50" autocomplete="off"
                       class="layui-input">
                <input type="text" name="activityName" lay-verify="money" maxlength="50" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label febs-form-item-require">字典编码：</label>
            <div class="layui-input-block">
                <input type="text" name="activityCode" lay-verify="money" maxlength="50" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label febs-form-item-require">类型：</label>
            <div class="layui-input-block">
                <input type="radio" lay-filter="typeRadio" name="type" value="0" title="自营" checked>
                <input type="radio" lay-filter="typeRadio" name="type" value="1" title="竞争对手">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label febs-form-item-require">默认值：</label>
            <div class="layui-input-block">
                <input type="text" name="activityValue" lay-verify="money" maxlength="50" autocomplete="off"
                       class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">备注：</label>
            <div class="layui-input-block">
                <input type="text" name="remark" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block" style="text-align: right;">
                <button class="layui-btn" lay-submit="" lay-filter="dict-add-form-submit" id="submit">提交</button>
                <button type="reset" class="layui-btn layui-btn-primary" id="reset">重置</button>
            </div>
        </div>
    </form>
    <p id="updateTrue" style="display: none;" th:text="${isUpdate}"></p>
</div>

<script>
    layui.use(['jquery', 'febs', 'laydate', 'form', 'layer'], function () {
        var $ = layui.jquery,
            laydate = layui.laydate,
            febs = layui.febs,
            layer = layui.layer,
            form = layui.form,
            $view = $('#oilPrice-add'),
            isUpdate = $('#updateTrue').text(),
            activityVal = localStorage.getItem('activityVal'),
            activityObj = JSON.parse(activityVal),
            $reset = $view.find('#reset'),
            $addForm = $view.find('form');

        form.verify({
            money: function(val, item) {
                if(!val){
                    return '该项不能为空'
                }
            }
        });
        form.render();
        laydate.render({
            elem: '#fromDate1',
            type: 'date',
            trigger: 'click'
        });
        if (isUpdate == 1) {
            initJobValue();
        }

        function initJobValue() {
            form.val("oilPrice-add-form", {
                "id": activityObj.id,
                "activityName": activityObj.activityName,
                "activityCode": activityObj.activityCode,
                "type": activityObj.type,
                "activityValue": activityObj.activityValue,
                "remark": activityObj.remark
            });
        }
        laydate.render({
            elem: '#fromTime1',
            type: 'time',
            trigger: 'click'
        });

        form.on('submit(dict-add-form-submit)', function (data) {
            if(isUpdate == 1){
                febs.post(ctx + 'shellActivity/shellActivityDictUpdate', data.field, function () {
                    febs.alert.success('修改成功');
                    layer.closeAll();
                    $('#febs-activity').find('#query').click();
                })
            } else {
                febs.post(ctx + 'shellActivity/shellActivityDictAdd', data.field, function () {
                    febs.alert.success('新增成功');
                    layer.closeAll();
                    $('#febs-activity').find('#query').click();
                });
                return false;
            }
        });
    });
</script>